#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N = 110;
map<int, int>mp;
int a[N];
int b[N];
int n, k;
int cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		int cnt = 0;
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i == 1)continue;
			int x= abs(a[i] - a[i - 1]);
			b[++cnt] = x;
			ans += x;
		}
		sort(b + 1, b + cnt + 1, cmp);
		
		for (int i = 1; i <= k - 1; i++) {
			ans -= b[i];
		}
		//int ans = 0;
		//int sum = 0;
		//int cnt1 = 0;
		//for (int i = 1; i <= n - 1; i++) {
		//	int x = abs(a[i + 1] - a[i]);
		//	if (!mp[x]) {
		//		cout << "x==" << x << endl;
		//		//if (!cnt1)continue;
		//		ans += x;
		//	}
		//}
		cout << ans  << endl;
	}
	return 0;
}